﻿// ---------------------------------------------------------------------------------------------
// <copyright file="Vertex.cs" company="Daniel Bradley">
//   Copyright (c) 2015 All Rights Reserved
// </copyright>
// <summary>
//   cf. https://github.com/danielrbradley/CycleDetection
// </summary>
// ---------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;

namespace Hiyoko.DependenciesSorter.CycleDetection
{
    public class Vertex<T>
    {
        #region Properties

        internal int Index { get; set; }
        internal int LowLink { get; set; }
        public T Value { get; set; }
        public ICollection<Vertex<T>> Dependencies { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the Vertex class.
        /// </summary>
        public Vertex()
        {
            Index = -1;
            Dependencies = new List<Vertex<T>>();
        }

        /// <summary>
        /// Initializes a new instance of the Vertex class.
        /// </summary>
        /// <param name="value">The vertex value.</param>
        public Vertex(T value)
            : this()
        {
            Value = value;
        }

        /// <summary>
        /// Initializes a new instance of the Vertex class.
        /// </summary>
        /// <param name="dependencies">The vertex dependencies.</param>
        public Vertex(IEnumerable<Vertex<T>> dependencies)
        {
            Index = -1;
            Dependencies = dependencies.ToList();
        }

        /// <summary>
        /// Initializes a new instance of the Vertex class.
        /// </summary>
        /// <param name="value">The vertex value.</param>
        /// <param name="dependencies">The vertex dependencies.</param>
        public Vertex(T value, IEnumerable<Vertex<T>> dependencies)
            : this(dependencies)
        {
            Value = value;
        }

        #endregion Constructors
    }
}
